home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / gui / AppTemp.lha / AppTemp / AppTemp.dat < prev    next >
Encoding:
Text File  |  1997-09-20  |  56.8 KB  |  1,919 lines

  1. «FILE:ARexx.j»
  2. /*
  3.  * «APPNAME» ARexx  (C) «YEAR» «APPOWNER»
  4.  *                  All Rights Under Copyright Reserved
  5.  *
  6.  * Version «VERSNUM»
  7.  *
  8.  * Written using «COMPILER»
  9.  * Using Magic User Interface (MUI) by Stefan Stuntz
  10.  *
  11.  * By «APPAUTH»
  12.  *
  13.  *
  14.  * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15.  * -------  ----        --------
  16.  *             ;
  17.  */
  18.  
  19. #include "common.h"
  20.  
  21. extern struct MyGlobals        MG;
  22. «FOREACH:WINDOW»
  23. extern struct «WSN»            «WSI»;
  24. «ENDEACH»
  25. extern char                    GL_szFault[256];
  26.  
  27.  
  28. /*
  29.  * AREXX HOOKS --------------------------------------
  30.  */
  31. SAVEDS ASM LONG RX_1ClearFunc      ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  32. {
  33.    ULONG ulForce;
  34.  
  35.  
  36.    ulForce = *((ULONG *)arg);
  37.    if ( ulForce )
  38.    {
  39.       return( RETURN_OK );
  40.    }
  41.    else if ( MUI_Request( MG.App, MG.WIN_«WSI», 0, NULL, "OK|*Cancel",
  42.                           "Are you sure you wish to clear all data?", NULL ) == 1 )
  43.    {
  44.       return( RETURN_OK );
  45.    }
  46.  
  47.    return( RETURN_ERROR );
  48. }
  49. SAVEDS ASM LONG RX_1OpenFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  50. {
  51.    ULONG  ulForce;
  52.    BOOL   fLoad = FALSE;
  53.    char  *pszFile;
  54.  
  55.  
  56.    pszFile =  ((char *)*arg);
  57.    ulForce = *((ULONG *)(arg+1));
  58.  
  59.    if ( ulForce )
  60.    {
  61.       fLoad = TRUE;
  62.    }
  63.    else if ( MUI_Request( MG.App, MG.WIN_«WSI», 0, NULL, "OK|*Cancel",
  64.                           "Data has been modified.\nAre you sure you wish to continue?", NULL ) == 1 )
  65.    {
  66.       fLoad = TRUE;
  67.    }
  68.  
  69.    if ( fLoad == TRUE )
  70.    {
  71.       if ( fnOpen( pszFile, TRUE ) )
  72.       {
  73.          return( RETURN_ERROR );
  74.       }
  75.       else
  76.       {
  77.          return( RETURN_OK );
  78.       }
  79.    }
  80.    return( RETURN_ERROR );
  81. }
  82. SAVEDS ASM LONG RX_1SaveasFunc     ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  83. {
  84.    char  *pszFile;
  85.  
  86.  
  87.    pszFile =  ((char *)*arg);
  88.  
  89.    if ( fnSave( pszFile, TRUE ) )
  90.    {
  91.       return( RETURN_ERROR );
  92.    }
  93.    else
  94.    {
  95.       return( RETURN_OK );
  96.    }
  97. }
  98. SAVEDS ASM LONG RX_1QuitFunc       ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  99. {
  100.    ULONG  ulForce;
  101.  
  102.  
  103.    ulForce = *((ULONG *)arg);
  104.  
  105.    if ( !ulForce )
  106.    {
  107.       if ( MUI_Request( MG.App, MG.WIN_«WSI», 0, NULL, "OK|*Cancel",
  108.                         "Are you sure you want to quit?", NULL ) == 1 )
  109.       {
  110.          MG.running = FALSE;
  111.       }
  112.    }
  113.    else
  114.    {
  115.       MG.running = FALSE;
  116.    }
  117.    return( RETURN_OK );
  118. }
  119. SAVEDS ASM LONG RX_4MoveWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  120. {
  121.    LONG   lX, lY;
  122.    char  *pszWindow;
  123.  
  124.  
  125.    pszWindow =  ((char *)*arg);
  126.    lX        = *((ULONG *)(arg+1));
  127.    lY        = *((ULONG *)(arg+2));
  128.  
  129. «FOREACH:WINDOW»
  130.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  MoveWindow( MG.WIN_«WSI», lX, lY );  }
  131. «ENDEACH»
  132.  
  133.    return( RETURN_OK );
  134. }
  135. SAVEDS ASM LONG RX_4SizeWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  136. {
  137.    LONG   lW, lH;
  138.    char  *pszWindow;
  139.  
  140.  
  141.    pszWindow =  ((char *)*arg);
  142.    lW        = *((ULONG *)(arg+1));
  143.    lH        = *((ULONG *)(arg+2));
  144.  
  145. «FOREACH:WINDOW»
  146.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  SizeWindow( MG.WIN_«WSI», lW, lH );  }
  147. «ENDEACH»
  148.  
  149.    return( RETURN_OK );
  150. }
  151. SAVEDS ASM LONG RX_4ChangeWdwFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  152. {
  153.    LONG   lX, lY, lW, lH;
  154.    char  *pszWindow;
  155.  
  156.  
  157.    pszWindow =  ((char *)*arg);
  158.    lX        = *((ULONG *)(arg+1));
  159.    lY        = *((ULONG *)(arg+2));
  160.    lW        = *((ULONG *)(arg+3));
  161.    lH        = *((ULONG *)(arg+4));
  162.  
  163. «FOREACH:WINDOW»
  164.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  ChangeWindowBox( MG.WIN_«WSI», lX, lY, lW, lH );  }
  165. «ENDEACH»
  166.  
  167.    return( RETURN_OK );
  168. }
  169. SAVEDS ASM LONG RX_4Wdw2FrontFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  170. {
  171.    char  *pszWindow;
  172.  
  173.  
  174.    pszWindow =  ((char *)*arg);
  175.  
  176. «FOREACH:WINDOW»
  177.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  WindowToFront( MG.WIN_«WSI» );  }
  178. «ENDEACH»
  179.  
  180.    return( RETURN_OK );
  181. }
  182. SAVEDS ASM LONG RX_4Wdw2BackFunc   ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  183. {
  184.    char  *pszWindow;
  185.  
  186.  
  187.    pszWindow =  ((char *)*arg);
  188.  
  189. «FOREACH:WINDOW»
  190.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  WindowToBack( MG.WIN_«WSI» );  }
  191. «ENDEACH»
  192.  
  193.    return( RETURN_OK );
  194. }
  195. SAVEDS ASM LONG RX_4ActivateWdwFunc( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  196. {
  197.    char  *pszWindow;
  198.  
  199.  
  200.    pszWindow =  ((char *)*arg);
  201.  
  202. «FOREACH:WINDOW»
  203.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  ActivateWindow( MG.WIN_«WSI» );  }
  204. «ENDEACH»
  205.  
  206.    return( RETURN_OK );
  207. }
  208. SAVEDS ASM LONG RX_4ZoomWdwFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  209. {
  210.    char  *pszWindow;
  211.  
  212.  
  213.    pszWindow =  ((char *)*arg);
  214.  
  215. «FOREACH:WINDOW»
  216.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  ZipWindow( MG.WIN_«WSI» );  }
  217. «ENDEACH»
  218.  
  219.    return( RETURN_OK );
  220. }
  221. SAVEDS ASM LONG RX_4UnzoomWdwFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  222. {
  223.    char  *pszWindow;
  224.  
  225.  
  226.    pszWindow =  ((char *)*arg);
  227.  
  228. «FOREACH:WINDOW»
  229.    if      ( strcmp( pszWindow, "«WSI»" ) == 0 ) {  ZipWindow( MG.WIN_«WSI» );  }
  230. «ENDEACH»
  231.  
  232.    return( RETURN_OK );
  233. }
  234. SAVEDS ASM LONG RX_6LockGUIFunc    ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  235. {
  236.    set( MG.App, MUIA_Application_Sleep, TRUE );
  237.    return( RETURN_OK );
  238. }
  239. SAVEDS ASM LONG RX_6UnlockGUIFunc  ( REG(a0) struct Hook *hook, REG(a2) Object *appl, REG(a1) ULONG *arg )
  240. {
  241.    set( MG.App, MUIA_Application_Sleep, FALSE );
  242.    return( RETURN_OK );
  243. }
  244.  
  245.  
  246. /*
  247.  * AREXX PROTOS -------------------------------------
  248.  */
  249. static const struct Hook RX_1ClearHook       = { {NULL, NULL}, (void *)RX_1ClearFunc      , NULL, NULL };
  250. static const struct Hook RX_1OpenHook        = { {NULL, NULL}, (void *)RX_1OpenFunc       , NULL, NULL };
  251. static const struct Hook RX_1SaveasHook      = { {NULL, NULL}, (void *)RX_1SaveasFunc     , NULL, NULL };
  252. static const struct Hook RX_1QuitHook        = { {NULL, NULL}, (void *)RX_1QuitFunc       , NULL, NULL };
  253. static const struct Hook RX_4MoveWdwHook     = { {NULL, NULL}, (void *)RX_4MoveWdwFunc    , NULL, NULL };
  254. static const struct Hook RX_4SizeWdwHook     = { {NULL, NULL}, (void *)RX_4SizeWdwFunc    , NULL, NULL };
  255. static const struct Hook RX_4ChangeWdwHook   = { {NULL, NULL}, (void *)RX_4ChangeWdwFunc  , NULL, NULL };
  256. static const struct Hook RX_4Wdw2FrontHook   = { {NULL, NULL}, (void *)RX_4Wdw2FrontFunc  , NULL, NULL };
  257. static const struct Hook RX_4Wdw2BackHook    = { {NULL, NULL}, (void *)RX_4Wdw2BackFunc   , NULL, NULL };
  258. static const struct Hook RX_4ActivateWdwHook = { {NULL, NULL}, (void *)RX_4ActivateWdwFunc, NULL, NULL };
  259. static const struct Hook RX_4ZoomWdwHook     = { {NULL, NULL}, (void *)RX_4ZoomWdwFunc    , NULL, NULL };
  260. static const struct Hook RX_4UnzoomWdwHook   = { {NULL, NULL}, (void *)RX_4UnzoomWdwFunc  , NULL, NULL };
  261. static const struct Hook RX_6LockGUIHook     = { {NULL, NULL}, (void *)RX_6LockGUIFunc    , NULL, NULL };
  262. static const struct Hook RX_6UnlockGUIHook   = { {NULL, NULL}, (void *)RX_6UnlockGUIFunc  , NULL, NULL };
  263.  
  264.  
  265. /*
  266.  * AREXX --------------------------------------------
  267.  */
  268. static struct MUI_Command rxcommands[] =
  269. {
  270.    // PROJECT-RELATED COMMANDS
  271.    { "NEW",    MC_TEMPLATE_ID,         ID_MENU_PROJECT_NEW,   NULL            },
  272.    { "CLEAR",  "FORCE/S",              1,                     &RX_1ClearHook  },
  273.    { "OPEN",   "FILENAME/A,FORCE/S",   2,                     &RX_1OpenHook   },
  274.    { "SAVE",   MC_TEMPLATE_ID,         ID_MENU_PROJECT_SAVE,  NULL            },
  275.    { "SAVEAS", "NAME/A",               1,                     &RX_1SaveasHook },
  276.    { "CLOSE",  MC_TEMPLATE_ID,         ID_MENU_PROJECT_QUIT,  NULL            },
  277.    { "QUIT",   "FORCE/S",              1,                     &RX_1QuitHook   },
  278.  
  279.    // WINDOW-RELATED COMMANDS
  280.    { "MOVEWINDOW",      "WINDOW/A,LEFTEDGE/N,TOPEDGE/N", 3, &RX_4MoveWdwHook     },
  281.    { "SIZEWINDOW",      "WINDOW/A,WIDTH/N,HEIGHT/N",     3, &RX_4SizeWdwHook     },
  282.    { "CHANGEWINDOW",    "WINDOW/A,LEFTEDGE/N,TOPEDGE/N,WIDTH/N,HEIGHT/N",
  283.                                                          5, &RX_4ChangeWdwHook   },
  284.    { "WINDOWTOFRONT",   "WINDOW/A",                      1, &RX_4Wdw2FrontHook   },
  285.    { "WINDOWTOBACK",    "WINDOW/A",                      1, &RX_4Wdw2BackHook    },
  286.    { "ACTIVATEWINDOW",  "WINDOW/A",                      1, &RX_4ActivateWdwHook },
  287.    { "ZOOMWINDOW",      "WINDOW/A",                      1, &RX_4ZoomWdwHook     },
  288.    { "UNZOOMWINDOW",    "WINDOW/A",                      1, &RX_4UnzoomWdwHook   },
  289.  
  290.    // APPLICATION-SPECIFIC COMMANDS
  291.  
  292.    // INTERFACE COMMANDS
  293.    { "LOCKGUI",   "", 0, &RX_6LockGUIHook    },
  294.    { "UNLOCKGUI", "", 0, &RX_6UnlockGUIHook  },
  295.  
  296.    { NULL, NULL, NULL, NULL }
  297. };
  298.  
  299. struct MUI_Command *RXCommands = (struct MUI_Command *)rxcommands;
  300. «ENDFILE»
  301.  
  302.  
  303. «FILE:common.hj»
  304. /*
  305.  * «APPNAME» Common Headers   (C) «YEAR» «APPOWNER»
  306.  *                            All Rights Under Copyright Reserved
  307.  *
  308.  * Version «VERSNUM»
  309.  *
  310.  * Written using «COMPILER»
  311.  * Using Magic User Interface (MUI) by Stefan Stuntz
  312.  *
  313.  * By «APPAUTH»
  314.  *
  315.  *
  316.  * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  317.  * -------  ----        --------
  318.  *             ;
  319.  */
  320.  
  321. #include <exec/libraries.h>
  322. #include <exec/types.h>
  323. #include <exec/memory.h>
  324. #include <exec/nodes.h>
  325. #include <exec/lists.h>
  326.  
  327. #include <devices/keymap.h>
  328.  
  329. #include <graphics/gfxbase.h>
  330. #include <graphics/displayinfo.h>
  331.  
  332. #include <intuition/intuitionbase.h>
  333. #include <intuition/intuition.h>
  334.  
  335. #include <dos/dos.h>
  336. #include <dos/datetime.h>
  337. #include <dos/rdargs.h>
  338. #include <dos/dostags.h>
  339.  
  340. #include <graphics/displayinfo.h>
  341. #include <graphics/gfxbase.h>
  342.  
  343. #include <libraries/asl.h>
  344. #include <libraries/dos.h>
  345. #include <libraries/dosextens.h>
  346. #include <libraries/gadtools.h>
  347. #include <libraries/locale.h>
  348. #include <libraries/mui.h>
  349.  
  350. #include <rexx/storage.h>
  351.  
  352. #include <workbench/startup.h>
  353. #include <workbench/workbench.h>
  354. #include <workbench/icon.h>
  355.  
  356. #include <clib/alib_protos.h>
  357.  
  358. #include <proto/asl.h>
  359. #include <proto/diskfont.h>
  360. #include <proto/dos.h>
  361. #include <proto/exec.h>
  362. #include <proto/gadtools.h>
  363. #include <proto/graphics.h>
  364. #include <proto/icon.h>
  365. #include <proto/intuition.h>
  366. #include <proto/locale.h>
  367. #include <proto/muimaster.h>
  368. #include <proto/utility.h>
  369. #include <proto/wb.h>
  370.  
  371. #include <stdlib.h>
  372. #include <string.h>
  373. #include <stdio.h>
  374. #include <ctype.h>
  375. #include <dos.h>
  376. #include <math.h>
  377.  
  378.  
  379. /*
  380.  * GENERAL DEFINES ----------------------------------
  381.  */
  382. #define FILEID_HEADER      "«APPBASE» «APPVERS»"
  383.  
  384. #define MAX( a,b )   ( ( (a) > (b) ) ? (a) : (b) )
  385. #define MIN( a,b )   ( ( (a) < (b) ) ? (a) : (b) )
  386. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  387.  
  388.  
  389. #define REG(x) register __ ## x
  390. #define ASM    __asm
  391. #define SAVEDS __saveds
  392.  
  393.  
  394. /*
  395.  * OBJECT IDs ------------------------------
  396.  */
  397. /***** MENUS *****/
  398. #define ID_MENU_PROJECT_NEW              1010
  399. #define ID_MENU_PROJECT_OPEN             1020
  400. #define ID_MENU_PROJECT_SAVE             1030
  401. #define ID_MENU_PROJECT_SAVEAS           1040
  402. #define ID_MENU_PROJECT_PRINT            1050
  403. #define ID_MENU_PROJECT_PRINTAS          1060
  404. #define ID_MENU_PROJECT_HIDE             1070
  405. #define ID_MENU_PROJECT_REVEAL           1080
  406. #define ID_MENU_PROJECT_CLOSE            1090
  407. #define ID_MENU_PROJECT_ABOUT            1100
  408. #define ID_MENU_PROJECT_ABOUTMUI         1110
  409. #define ID_MENU_PROJECT_EXITLEVEL        1120
  410. #define ID_MENU_PROJECT_QUIT             1130
  411.  
  412. #define ID_MENU_EDIT_CUT                 2010
  413. #define ID_MENU_EDIT_COPY                2020
  414. #define ID_MENU_EDIT_PASTE               2030
  415. #define ID_MENU_EDIT_ERASE               2040
  416. #define ID_MENU_EDIT_UNDO                2050
  417. #define ID_MENU_EDIT_REDO                2060
  418.  
  419. #define ID_MENU_MACROS_STARTLEARNING     3010
  420. #define ID_MENU_MACROS_STOPLEARNING      3020
  421. #define ID_MENU_MACROS_ASSIGNMACRO       3030
  422. #define ID_MENU_MACROS_LOAD              3040
  423. #define ID_MENU_MACROS_SAVE              3050
  424.  
  425. #define ID_MENU_SETTINGS_MUI             4010
  426. #define ID_MENU_SETTINGS_CREATEICONS     4020
  427. #define ID_MENU_SETTINGS_LOAD            4030
  428. #define ID_MENU_SETTINGS_SAVE            4040
  429. #define ID_MENU_SETTINGS_SAVEAS          4050
  430.  
  431. #define ID_MENU_USER_MACRO1              5010
  432. #define ID_MENU_USER_MACRO2              5020
  433. #define ID_MENU_USER_MACRO3              5030
  434. #define ID_MENU_USER_MACRO4              5040
  435. #define ID_MENU_USER_MACRO5              5050
  436. #define ID_MENU_USER_MACRO6              5060
  437. #define ID_MENU_USER_MACRO7              5070
  438. #define ID_MENU_USER_MACRO8              5080
  439. #define ID_MENU_USER_MACRO9              5090
  440. #define ID_MENU_USER_MACRO10             5100
  441.  
  442.  
  443. /*
  444.  * MESSAGE IDs -----------------------------
  445.  */
  446. «FOREACH:WINDOW»
  447. /***** WINDOW: «WSI» *****/
  448. #define ID_BUT_«WSI»_OK              «GADGETID:998»
  449. #define ID_BUT_«WSI»_CANCEL          «GADGETID:999»
  450. «ENDEACH»
  451.  
  452.  
  453. /*
  454.  * JMH-APP-TEMPLATE FUNCTION PROTOTYPES ----
  455.  */
  456. void    JMH_About          ( void );
  457. LONG    JMH_Error          ( char *, APTR, BOOL, char *, char *, LONG );
  458. BOOL    JMH_FileReq        ( APTR, UBYTE *, BOOL, BOOL, UBYTE *, UWORD );
  459. VOID    JMH_InitVars       ( void );
  460. ULONG   JMH_LaunchProgram  ( BOOL, UBYTE *, BOOL );
  461. void    JMH_Quit           ( char * );
  462. void    JMH_Startup        ( int, char *[] );
  463. void    JMH_WindowTitle    ( APTR );
  464.  
  465. APTR    JMH_ShowWaitBox    ( APTR, UBYTE *, UBYTE * );
  466. BOOL    JMH_HideWaitBox    ( APTR, APTR );
  467. USHORT  JMH_Strip          ( UBYTE *, UBYTE * );
  468. USHORT  JMH_CStrip         ( UBYTE *, UBYTE * );
  469. UBYTE  *JMH_PadStr         ( UBYTE *, UBYTE, BYTE, USHORT );
  470. double  JMH_Round          ( double, BYTE );
  471. BOOL    JMH_IsNumberValid  ( UBYTE *, BYTE );
  472. BOOL    JMH_VerifyLegitDate( UBYTE * );
  473.  
  474.  
  475. /*
  476.  * STRUCTURE DEFINITIONS -------------------
  477.  */
  478. struct MyGlobals {
  479.    APTR  App;
  480. «FOREACH:WINDOW»
  481.    APTR  WIN_«WSI»;
  482. «ENDEACH»
  483.  
  484.    struct DiskObject *dobj_App, *dobj_Proj;
  485.    UBYTE  szProjectSpec[ FMSIZE+1 ];
  486.  
  487.    BOOL   running;
  488. };
  489.  
  490. «FOREACH:WINDOW»
  491. struct «WSN» {
  492.    APTR  BUT_OK,
  493.          BUT_Cancel;
  494. };
  495. «ENDEACH»
  496.  
  497.  
  498. /*
  499.  * APPLICATION FUNCTION PROTOTYPES ------------------
  500.  */
  501. BOOL fnOpen( UBYTE *, BOOL );
  502. BOOL fnSave( UBYTE *, BOOL );
  503.  
  504. «FOREACH:WINDOW»
  505. BOOL fnConstruct«WSN»( void );
  506. BOOL fnInit«WSN»( void );
  507. BOOL fnDestruct«WSN»( BOOL );
  508. void fnClear«WSN»( void );
  509. «ENDEACH»
  510. «ENDFILE»
  511.  
  512.  
  513. «FILE:jmh.j»
  514. /*
  515.  * JMH App Template  (C) «YEAR» «APPOWNER»
  516.  *                   All Rights Under Copyright Reserved
  517.  *
  518.  * Version «VERSNUM»
  519.  *
  520.  * Written using «COMPILER»
  521.  * Using Magic User Interface (MUI) by Stefan Stuntz
  522.  *
  523.  * By «APPAUTH»
  524.  *
  525.  *
  526.  * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  527.  * -------  ----        --------
  528.  *             ;
  529.  */
  530.  
  531. #include "common.h"
  532.  
  533. /**
  534.  **   G L O B A L   V A R I A B L E S  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  535.  **/
  536. extern struct MyGlobals  MG;
  537. extern UBYTE             GL_szFault[256];
  538. extern struct DosBase   *DosBase;
  539.  
  540.  
  541. #ifdef DEBUG_REXX
  542. /**
  543.  **   D E B U G   H O O K S  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  544.  **/
  545. SAVEDS ASM APTR fnRexxDebug(REG(a0) struct Hook *hook, REG(a2) APTR app, REG(a1) struct RexxMsg *pRexxMsg )
  546. {
  547.    UBYTE *pszAppTitle;
  548.    SHORT  i;
  549.  
  550.  
  551.    get( app, MUIA_Application_Title, &pszAppTitle );
  552.    printf( "***** MUI REXX DEBUG HOOK FOR %s *****\n", pszAppTitle );
  553.    printf( "   rm_Action  = %ld\n", pRexxMsg->rm_Action );
  554.    printf( "   rm_Result1 = %ld\n", pRexxMsg->rm_Result1 );
  555.    printf( "   rm_Result2 = %ld\n", pRexxMsg->rm_Result2 );
  556.    for ( i = 0; i < 15; i++ )
  557.    {
  558.       printf( "   rm_Args[%d] = '%s'\n", i, pRexxMsg->rm_Args[i] );
  559.    }
  560.    printf( "\n" );
  561.    return(0);
  562. }
  563. static struct Hook hRexxDebugHook =
  564. {
  565.    {NULL, NULL},
  566.    (void *)fnRexxDebug,
  567.    NULL, NULL
  568. };
  569. #endif /* DEBUG_REXX */
  570.  
  571.  
  572. /**
  573.  **   S U B R O U T I N E S  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  574.  **/
  575. //
  576. // JMH_About(): show program info, basename, author, free memory, etc...
  577. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  578. void JMH_About( void )
  579. {
  580.    char  *pszVersion, *pszAuth, *pszCopyright, *pszBase, *pszDescrip;
  581.    char   szAbout[1024];
  582.    ULONG  ulChipFree, ulFastFree;
  583.  
  584.  
  585.    get( MG.App, MUIA_Application_Version,     &pszVersion );
  586.    get( MG.App, MUIA_Application_Author,      &pszAuth );
  587.    get( MG.App, MUIA_Application_Copyright,   &pszCopyright );
  588.    get( MG.App, MUIA_Application_Base,        &pszBase );
  589.    get( MG.App, MUIA_Application_Description, &pszDescrip );
  590.  
  591.    ulChipFree = AvailMem( MEMF_CHIP );
  592.    ulFastFree = AvailMem( MEMF_FAST );
  593.  
  594.    sprintf( szAbout, "\33c\33b%s\n\33c%s\n\33c%s\n\n\33c%s %s\n\n%s\n\n\
  595. Graphics memory: %lu\nOther memory: %lu\n\nUsing Magic User Interface (MUI) by Stefan Stuntz",
  596.                      pszVersion+6,
  597.                      pszAuth,
  598.                      pszCopyright,
  599.                      "BASENAME:",
  600.                      pszBase,
  601.                      pszDescrip,
  602.                      ulChipFree,
  603.                      ulFastFree
  604.           );
  605.  
  606.    MUI_Request( MG.App, NULL, 0, NULL, "*OK", szAbout, NULL );
  607. }
  608.  
  609. //
  610. // JMH_Error(): error routine that also provides help
  611. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  612. LONG JMH_Error( char *pszMsg, APTR pWindowObj, BOOL fARexx,
  613.                 char *pszHelpFile, char *pszHelpNode, LONG lHelpLine )
  614. {
  615.    LONG l;
  616.    char *pszResponses;
  617.    char *pszHelp   = "*OK|Help";
  618.    char *pszNoHelp = "*OK";
  619.  
  620.  
  621.    if ( fARexx )
  622.    {
  623.       set( MG.App, MUIA_Application_RexxMsg, pszMsg );
  624.    }
  625.    else
  626.    {
  627.       if ( pszHelpFile )   pszResponses = pszHelp;
  628.       else                 pszResponses = pszNoHelp;
  629.  
  630. redisplay:
  631.       l = MUI_Request( MG.App, pWindowObj, 0, NULL, "*OK|Help", pszMsg, NULL );
  632.       if ( l == 0 )
  633.       {
  634.          if ( pszHelpFile && pszHelpNode )
  635.          {
  636.             DoMethod( MG.App, MUIM_Application_ShowHelp, pWindowObj,
  637.                       pszHelpFile, pszHelpNode, lHelpLine );
  638.          }
  639.          else
  640.          {
  641.             MUI_Request( MG.App, pWindowObj, 0, NULL, "*OK", "No help is available for this topic.", NULL );
  642.          }
  643.          goto redisplay;
  644.       }
  645.    }
  646.    return( l );
  647. }
  648.  
  649. //
  650. // JMH_FileReq(): Pop up a file requester...
  651. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  652. BOOL JMH_FileReq( APTR pWindowObj, UBYTE *pszFreqHail, BOOL fSaveMode, BOOL fDirMode, UBYTE *pszSaveBuf, UWORD uwSaveBufSize )
  653. {
  654.    char  *psz;
  655.    static char  szPathPart[ FMSIZE+1 ], szFilePart[ FMSIZE+1 ];
  656.  
  657.    struct Window        *pWindow = NULL;
  658.    struct FileRequester *pFReq   = NULL;
  659.  
  660.  
  661.    get( pWindowObj, MUIA_Window, &pWindow );
  662.    if ( pFReq = MUI_AllocAslRequestTags( ASL_FileRequest, TAG_DONE ) )
  663.    {
  664.       strcpy( szPathPart, pszSaveBuf );
  665.       psz = FilePart( szPathPart );
  666.       if ( psz )
  667.       {
  668.          strcpy( szFilePart, psz );
  669.          *psz = 0;
  670.       }
  671.       else
  672.       {
  673.          strcpy( szFilePart, "" );
  674.       }
  675.  
  676.       if ( MUI_AslRequestTags( pFReq,
  677.                                ASLFR_Window        , pWindow,
  678.                                ASLFR_PrivateIDCMP  , TRUE,
  679.                                ASLFR_TitleText     , pszFreqHail,
  680.                                ASLFR_InitialDrawer , szPathPart,
  681.                                ASLFR_InitialFile   , szFilePart,
  682.                                ASLFR_DoSaveMode    , fSaveMode,
  683.                                ASLFR_DrawersOnly   , fDirMode,
  684.                                TAG_DONE ) )
  685.       {
  686.          // set the new contents for our string gadget
  687.          *pszSaveBuf = 0;
  688.          strncpy( pszSaveBuf, pFReq->fr_Drawer, uwSaveBufSize-1 );
  689.          AddPart( pszSaveBuf, pFReq->fr_File,   uwSaveBufSize-1 );
  690.       }
  691.       else
  692.       {
  693.          MUI_FreeAslRequest( pFReq );
  694.          return( FALSE );
  695.       }
  696.  
  697.       MUI_FreeAslRequest( pFReq );
  698.    }
  699.    else
  700.    {
  701.       return( FALSE );
  702.    }
  703.  
  704.    return( TRUE );
  705. }
  706.  
  707. //
  708. // JMH_InitVars(): initialize variables to default values
  709. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  710. VOID JMH_InitVars()
  711. {
  712.    //
  713.    // initialize variables...
  714.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  715.    GL_szFault[0] = 0;
  716.  
  717.    //
  718.    // init window objects to NULL
  719.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  720. «FOREACH:WINDOW»
  721.    MG.WIN_«WSI» = NULL;
  722. «ENDEACH»
  723.  
  724.    //
  725.    // open libraries
  726.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  727.    MUIMasterBase = OpenLibrary(MUIMASTER_NAME, «MUIMASTER_VERSION»);
  728.    if (!MUIMasterBase) JMH_Quit("Cannot open muimaster.library" );
  729.  
  730. «IF:ASL_INCL»
  731.    AslBase = OpenLibrary("asl.library",«ASL_VERSION»);
  732.    if (!AslBase) JMH_Quit("Cannot open asl.library «ASL_VERSION»+");
  733.  
  734. «ENDIF»
  735. «IF:DATATYPES_INCL»
  736.    DataTypesBase = (struct Library *)OpenLibrary("datatypes.library",«DATATYPES_VERSION»);
  737.    if (!DataTypesBase) JMH_Quit("Cannot open datatypes.library «DATATYPES_VERSION»+" );
  738.  
  739. «ENDIF»
  740. «IF:DISKFONT_INCL»
  741.    DiskfontBase = (struct Library *)OpenLibrary("diskfont.library", «DISKFONT_VERSION»);
  742.    if (!DiskfontBase) JMH_Quit("Cannot open diskfont.library «DISKFONT_VERSION»+");
  743.  
  744. «ENDIF»
  745.    DosBase = (struct DosBase *)OpenLibrary( "dos.library", «DOS_VERSION» );
  746.    if ( !DosBase ) JMH_Quit("Cannot open dos.library «DOS_VERSION»+");
  747.  
  748. «IF:GADTOOLS_INCL»
  749.    GadToolsBase = (struct Library *)OpenLibrary("gadtools.library", «GADTOOLS_VERSION»);
  750.    if (!GadToolsBase) JMH_Quit("Cannot open gadtools.library «GADTOOLS_VERSION»+");
  751.  
  752. «ENDIF»
  753.    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",«GFX_VERSION»);
  754.    if (!GfxBase) JMH_Quit("Cannot open graphics.library «GFX_VERSION»+");
  755.  
  756.    IconBase = (struct Library *)OpenLibrary("icon.library",«ICON_VERSION»);
  757.    if (!IconBase) JMH_Quit("Cannot open icon.library «ICON_VERSION»+");
  758.  
  759. «IF:IFFPARSE_INCL»
  760.    IFFParseBase = (struct Library *)OpenLibrary("iffparse.library",«IFFPARSE_VERSION»);
  761.    if (!IFFParseBase) JMH_Quit("Cannot open iffparse.library «IFFPARSE_VERSION»+");
  762.  
  763. «ENDIF»
  764.    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",«INTUITION_VERSION»);
  765.    if (!IntuitionBase) JMH_Quit("Cannot open intuition.library «INTUITION_VERSION»+");
  766.  
  767. «IF:LOCALE_INCL»
  768.    LocaleBase = OpenLibrary("locale.library",«LOCALE_VERSION»);
  769.    if (!LocaleBase) JMH_Quit("Cannot open locale.library «LOCALE_VERSION»+");
  770.  
  771. «ENDIF»
  772. «IF:REALTIME_INCL»
  773.    RealTimeBase = OpenLibrary("realtime.library", «REALTIME_VERSION»);
  774.    if (!RealTimeBase) JMH_Quit("Cannot open realtime.library «REALTIME_VERSION»+" );
  775.  
  776. «ENDIF»
  777.    UtilityBase = (struct Library *)OpenLibrary("utility.library",«UTILITY_VERSION»);
  778.    if (!UtilityBase) JMH_Quit("Cannot open utility.library «UTILITY_VERSION»+" );
  779.  
  780. «IF:WORKBENCH_INCL»
  781.    WorkbenchBase = (struct Library *)OpenLibrary("workbench.library",«WORKBENCH_VERSION»);
  782.    if (!WorkbenchBase) JMH_Quit("Cannot open workbench.library «WORKBENCH_VERSION»+");
  783. «ENDIF»
  784. }
  785.  
  786. //
  787. // JMH_LaunchProgram(): launch a system program
  788. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  789. ULONG JMH_LaunchProgram( BOOL fARexx, UBYTE *pszProgram, BOOL fAsync )
  790. {
  791.    ULONG  rc = RETURN_OK;     // assume ARexx success...
  792.    LONG   lStat;
  793.    UBYTE  szBuf[512];
  794.  
  795.  
  796.    if ( !fAsync )    set( MG.App, MUIA_Application_Sleep, TRUE );
  797.  
  798.    lStat = SystemTags( pszProgram, SYS_Asynch, fAsync, TAG_DONE, TAG_DONE );
  799.    if ( lStat != 0 )
  800.    {
  801.       if ( lStat > 0 )
  802.       {
  803.          sprintf( szBuf, "Unable to launch %s because", pszProgram );
  804.          Fault( IoErr(),
  805.                 szBuf,
  806.                 GL_szFault,
  807.                 sizeof( GL_szFault ) );
  808.       }
  809.       else
  810.       {
  811.          sprintf( GL_szFault, "Unable to launch %s!", pszProgram );
  812.       }
  813.  
  814.       JMH_Error( GL_szFault, NULL, fARexx, "«HELPFILE»", "errors", 0 );
  815.       rc = RETURN_ERROR;
  816.    }
  817.  
  818.    if ( !fAsync )    set( MG.App, MUIA_Application_Sleep, FALSE );
  819.  
  820.    return( rc );
  821. }
  822.  
  823. //
  824. // JMH_Quit(): close down everything we've opened and JMH_Quit
  825. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  826. void JMH_Quit( char *t )
  827. {
  828.    char  szQuitBuf[256+20];
  829.  
  830.  
  831.    if (t)
  832.    {
  833.       sprintf( szQuitBuf, "%s\nExiting...", t );
  834.       MUI_Request( MG.App, NULL, 0, NULL, "*OK", szQuitBuf, NULL );
  835.    }
  836.  
  837.    // free app object
  838.    if ( MG.App )        MUI_DisposeObject( MG.App );
  839.  
  840.    // free disk object (project icon)
  841.    if ( MG.dobj_Proj )  FreeDiskObject( MG.dobj_Proj );
  842.  
  843.    // free disk object (icon)
  844.    if ( MG.dobj_App )   FreeDiskObject( MG.dobj_App );
  845.  
  846.    // close libraries
  847. «IF:WORKBENCH_INCL»
  848.    if (WorkbenchBase)   CloseLibrary(WorkbenchBase);
  849. «ENDIF»
  850.    if (UtilityBase)     CloseLibrary(UtilityBase);
  851. «IF:REALTIME_INCL»
  852.    if (RealTimeBase)    CloseLibrary(RealTimeBase);
  853. «ENDIF»
  854. «IF:LOCALE_INCL»
  855.    if (LocaleBase)      CloseLibrary(LocaleBase);
  856. «ENDIF»
  857.    if (IntuitionBase)   CloseLibrary((struct Library *)IntuitionBase);
  858. «IF:IFFPARSE_INCL»
  859.    if (IFFParseBase)    CloseLibrary(IFFParseBase);
  860. «ENDIF»
  861.    if (IconBase)        CloseLibrary(IconBase);
  862.    if (GfxBase)         CloseLibrary((struct Library *)GfxBase);
  863. «IF:GADTOOLS_INCL»
  864.    if (GadToolsBase)    CloseLibrary(GadToolsBase);
  865. «ENDIF»
  866.    if (DosBase)         CloseLibrary((struct Library *)DosBase);
  867. «IF:DISKFONT_INCL»
  868.    if (DiskfontBase)    CloseLibrary(DiskfontBase);
  869. «ENDIF»
  870. «IF:DATATYPES_INCL»
  871.    if (DataTypesBase)   CloseLibrary(DataTypesBase);
  872. «ENDIF»
  873. «IF:ASL_INCL»
  874.    if (AslBase)         CloseLibrary(AslBase);
  875. «ENDIF»
  876.    if (MUIMasterBase)   CloseLibrary(MUIMasterBase);
  877.  
  878.    exit(0);
  879. }
  880.  
  881. //
  882. // JMH_Startup(): handle arguments, setup environment, init vars/GUI...
  883. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  884. void JMH_Startup( int argc, char *argv[] )
  885. {
  886.    static char       *programname;
  887.    static char        programpath[ FMSIZE+2 ];
  888.    BPTR               tmplock;
  889.    struct WBStartup  *WBenchMsg   = NULL;
  890. //   char              *psz;
  891.    struct CLIArgs
  892.    {
  893.       UBYTE *pszProject;
  894. //    LONG   moreparamshere;
  895. //    LONG   moreparamshere;
  896. //    LONG   moreparamshere;
  897.    } argarray = { 0 };
  898.    struct RDArgs     *rda, *rdas;
  899.    static UBYTE      *pszCLITemplate = "PROJECTFILE";
  900.    static UBYTE      *pszCLIHelp     = "«APPNAME» «APPVERS»  (C) «YEAR»  «APPAUTH»\n";
  901.    UBYTE            **ttypes;
  902.  
  903.  
  904.    JMH_InitVars();
  905.  
  906.    // run from Workbench or CLI/Shell?
  907.    if ( argc > 0 )
  908.    {
  909.       // set defaults
  910.       strcpy( MG.szProjectSpec  , "" );
  911.  
  912.       // get opts from command line
  913.       if ( rdas = AllocDosObject( DOS_RDARGS, NULL ) )
  914.       {
  915.          rdas->RDA_ExtHelp = pszCLIHelp;
  916.  
  917.          if ( rda = ReadArgs( pszCLITemplate, (LONG *)&argarray, rdas ) )
  918.          {
  919.             if ( argarray.pszProject )
  920.             {
  921.                strcpy( MG.szProjectSpec, argarray.pszProject );
  922.             }
  923.             FreeArgs( rda );
  924.          }
  925.          FreeDosObject( DOS_RDARGS, rdas );
  926.       }
  927.  
  928.       //
  929.       // get program name so we can lock icon...
  930.       // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  931.       GetProgramName( programpath, FMSIZE );
  932.       programname = FilePart( programpath );
  933.    }
  934.    else
  935.    {
  936.       // get opts from TOOLTYPES in icon
  937.       strcpy( MG.szProjectSpec, "" );   // passed as param under WB
  938.  
  939.       ttypes = ArgArrayInit( argc, argv );
  940.  
  941.       // parse tooltypes here...
  942. //      psz = ArgString( ttypes, "CONFIGFILE", "" );
  943. //      strcpy( MG.szProjectSpec, psz );
  944.  
  945. //      psz = ArgString( ttypes, "NOGUI", "FALSE" );
  946. //      if ( strcmpi( psz, "TRUE" ) == 0 )
  947. //      {
  948. //         MG.fBeQuiet = TRUE;
  949. //      }
  950. //      else
  951. //      {
  952. //         MG.fBeQuiet = FALSE;
  953. //      }
  954.  
  955.       ArgArrayDone();
  956.  
  957.       //
  958.       // get program name so we can lock icon...
  959.       // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  960.       WBenchMsg   = (struct WBStartup *)argv;
  961.       programname = WBenchMsg->sm_ArgList->wa_Name;
  962.  
  963.       tmplock  = Lock( programname, ACCESS_READ );
  964.       NameFromLock( tmplock, programpath, FMSIZE );
  965.       UnLock( tmplock );
  966.    }
  967.  
  968.    // try to get disk object (application icon)
  969.    MG.dobj_App = GetDiskObject( programname );
  970.  
  971.    // try to get disk object (project icon)
  972.    MG.dobj_Proj = GetDiskObjectNew( "PROGDIR:icons/def_project" );
  973.  
  974.    //
  975.    // set up the MUI application object
  976.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  977.    MG.App = ApplicationObject,
  978.       MUIA_Application_Title      , "«APPTITLE»",
  979.       MUIA_Application_Version    , "«APPVERS»",
  980.       MUIA_Application_Copyright  , "«APPCOPYR»",
  981.       MUIA_Application_Author     , "«APPAUTH»",
  982.       MUIA_Application_Description, "«APPDESC»",
  983.       MUIA_Application_Base       , "«APPBASE»",
  984.       MUIA_Application_DiskObject , MG.dobj_App,
  985. #ifdef DEBUG_REXX
  986.       MUIA_Application_RexxHook   , &hRexxDebugHook,
  987. #endif
  988.       MUIA_Application_HelpFile   , "«HELPFILE»",
  989.       End;
  990.  
  991.    if ( !MG.App )
  992.       JMH_Quit( "Failed to create Application." );
  993. }
  994.  
  995. //
  996. // JMH_VerifyLegitDate()
  997. // RETURNS:       BOOL - TRUE if legitimate
  998. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  999. BOOL JMH_VerifyLegitDate( UBYTE pszDate[] )
  1000. {
  1001.    USHORT  usYear, usMonth, usDay;
  1002.    UBYTE   szYear[5], szMonth[3], szDay[3];
  1003.    BOOL    rc;                               // return code
  1004.  
  1005.    static USHORT usDaysPerMo[] = {
  1006.       31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1007.    };
  1008.  
  1009.  
  1010.    sprintf( szYear,  "%-4.4s", &pszDate[6] );
  1011.    sprintf( szMonth, "%-2.2s", &pszDate[0] );
  1012.    sprintf( szDay,   "%-2.2s", &pszDate[3] );
  1013.    usYear  = atoi( szYear );
  1014.    usMonth = atoi( szMonth );
  1015.    usDay   = atoi( szDay );
  1016.  
  1017.    if ( ( usYear % 4 ) == 0 )
  1018.    {
  1019.       usDaysPerMo[1] = 29;
  1020.    }
  1021.    else
  1022.    {
  1023.       usDaysPerMo[1] = 28;
  1024.    }
  1025.  
  1026.    if ( ( usMonth < 1 ) || ( usMonth > 12 ) )
  1027.    {
  1028.       rc = FALSE;
  1029.    }
  1030.    else
  1031.    {
  1032.       if ( ( usDay < 1 ) || ( usDay > usDaysPerMo[usMonth-1] ) )
  1033.       {
  1034.          rc = FALSE;
  1035.       }
  1036.       else
  1037.       {
  1038.          rc = TRUE;
  1039.       }
  1040.    }
  1041.    return( rc );
  1042. }
  1043.  
  1044. //
  1045. // JMH_WindowTitle(): set window title as PROGNAME: current-filespec
  1046. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1047. void JMH_WindowTitle( APTR win )
  1048. {
  1049.    static char  szWindowTitle[256];
  1050.    char        *pszTitle;
  1051.  
  1052.  
  1053.    get( MG.App, MUIA_Application_Title, &pszTitle );
  1054.    sprintf( szWindowTitle, "%s: ", pszTitle );
  1055.    strncat( szWindowTitle, MG.szProjectSpec, 256-32-1 );
  1056.    szWindowTitle[255] = 0;
  1057.    set( win, MUIA_Window_Title, szWindowTitle );
  1058. }
  1059.  
  1060. //
  1061. // JMH_ShowWaitBox(): show wait box
  1062. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1063. APTR JMH_ShowWaitBox( APTR app, UBYTE *title, UBYTE *text )
  1064. {
  1065.    Object *pWaitBox;
  1066.  
  1067.  
  1068.    pWaitBox = WindowObject,
  1069.       MUIA_Window_Title, title,
  1070.       MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  1071.       WindowContents, VGroup,
  1072.          Child, FloattextObject,
  1073.             MUIA_Floattext_Text, text,
  1074.             End,
  1075.          End,
  1076.       End;
  1077.    if ( pWaitBox )
  1078.    {
  1079.       // add window to Application object
  1080.       DoMethod( app, OM_ADDMEMBER, pWaitBox );
  1081.  
  1082.       set( pWaitBox, MUIA_Window_Open, TRUE );
  1083.    }
  1084.  
  1085.    return( pWaitBox );
  1086. }
  1087.  
  1088. //
  1089. // JMH_HideWaitBox(): hide wait box
  1090. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1091. BOOL JMH_HideWaitBox( APTR app, APTR pWaitBox )
  1092. {
  1093.    BOOL  fOpen;
  1094.  
  1095.  
  1096.    get( pWaitBox, MUIA_Window_Open, &fOpen );
  1097.    if ( fOpen )
  1098.    {
  1099.       set( pWaitBox, MUIA_Window_Open, FALSE );
  1100.       DoMethod( app, OM_REMMEMBER, pWaitBox );
  1101.    }
  1102.  
  1103.    return( fOpen );
  1104. }
  1105.  
  1106. //
  1107. // JMH_Strip(): strip chars from string
  1108. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1109. USHORT JMH_Strip( UBYTE *pszStrip, UBYTE *pszStripChars )
  1110. {
  1111.   UBYTE *pszOrig,  // used to access each character in the given string.
  1112.         *pszPack;  // used to place (pack) characters not being stripped
  1113.                    // back into given string.
  1114.  
  1115.   for ( pszOrig = pszPack = pszStrip; *pszOrig; pszOrig++ )
  1116.   {
  1117.     //
  1118.     // When current character of the original string is one of the characters
  1119.     // in the strip string do not place it in the stripped (packed) string.
  1120.     //
  1121.     if ( strchr( pszStripChars, *pszOrig ) == NULL )
  1122.     {
  1123.       *( pszPack++ ) = *pszOrig;
  1124.     }
  1125.   }
  1126.   *pszPack = 0;
  1127.  
  1128.   return( (USHORT)strlen( pszStrip ) );
  1129. }
  1130.  
  1131. //
  1132. // JMH_CStrip(): strip chars not in KeepString
  1133. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1134. USHORT JMH_CStrip( UBYTE *pszStrip, UBYTE *pszKeepChars )
  1135. {
  1136.   UBYTE *pszOrig,  // used to access each character in the given string.
  1137.         *pszPack;  // used to place (pack) characters not being stripped
  1138.                    // back into given string.
  1139.  
  1140.   for ( pszOrig = pszPack = pszStrip; *pszOrig; pszOrig++ )
  1141.   {
  1142.     //
  1143.     // When current character of the original string is not one of the chars
  1144.     // in the keep string do not place it in the stripped (packed) string.
  1145.     //
  1146.     if ( strchr( pszKeepChars, *pszOrig ) != NULL )
  1147.     {
  1148.       *( pszPack++ ) = *pszOrig;
  1149.     }
  1150.   }
  1151.   *pszPack = 0;
  1152.  
  1153.   return( (USHORT)strlen( pszStrip ) );
  1154. }
  1155.  
  1156. //
  1157. // JMH_PadStr(): pads a string from left or right with given character
  1158. // PARAMETERS:  UCHAR *szPad   - String to be padded
  1159. //              UCHAR  chPad   - character to pad string with
  1160. //              BYTE   bPadDir - Specifies where to pad string
  1161. //                               Valid values are:
  1162. //                                  -1: left side
  1163. //                                  +1: right side
  1164. //              USHORT usSize  - desired size of the padded string
  1165. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1166. UBYTE *JMH_PadStr( UBYTE *pszPad, UBYTE chPad, BYTE bPadDir, USHORT usSize )
  1167. {
  1168.   USHORT usStrLen,    // Length of the given string before padding
  1169.          usPadChars;  // Number of Pad characters that need to be added to
  1170.                       // the given string
  1171.  
  1172.   if ( (usStrLen = strlen( pszPad )) < usSize )
  1173.   {
  1174.     usPadChars = usSize - usStrLen;
  1175.     if ( bPadDir == -1 )
  1176.     {
  1177.       //
  1178.       // Pad from the left
  1179.       //
  1180.       memmove( (pszPad + usPadChars), pszPad, usStrLen + 1);
  1181.       memset( pszPad, chPad, usPadChars );
  1182.     }
  1183.     else
  1184.     {
  1185.       //
  1186.       // Pad from the right
  1187.       //
  1188.       memset( (pszPad + usStrLen), chPad, usPadChars );
  1189.       *(pszPad + usSize) = 0;
  1190.     }
  1191.   }
  1192.  
  1193.   return( pszPad );
  1194. }
  1195.  
  1196. //
  1197. // JMH_Round(): round a double to a given number of decimals
  1198. // PARAMETERS:  double dblValue  - Value to be rounded.
  1199. //              BYTE   bDecimals - Number of decimal places to round
  1200. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1201. double JMH_Round( double dblValue, BYTE bDecimals )
  1202. {
  1203.   SHORT  sSign;
  1204.   double dblFactor,
  1205.          dblInt;
  1206.  
  1207.   sSign     = ( dblValue >= 0.0 ) ? 1 : -1;
  1208.   dblFactor = pow( (double)10, (double)bDecimals );
  1209.   dblInt    = floor( dblValue * (double)sSign );
  1210.  
  1211.   return( ( dblInt + floor( ( dblValue * sSign - dblInt ) * dblFactor + 0.51 )
  1212.             / dblFactor) * sSign );
  1213. }
  1214.  
  1215. //
  1216. // JMH_IsNumberValid(): does string contain only numeric chars?
  1217. // PARAMETERS:  UBYTE *pszNum    - Numeric string to be verified
  1218. //               BYTE  bType:  1 = Positive-Only Integer
  1219. //                             2 = Positive-Only Float
  1220. //                            -1 = Positive or Negative Integer
  1221. //                            -2 = Positive or Negative Float
  1222. //                             0 = Positive or Negative Float (default)
  1223. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1224. BOOL JMH_IsNumberValid( UBYTE *pszNum, BYTE bType )
  1225. {
  1226.    USHORT  us = 0;
  1227.  
  1228.    static UBYTE *pszValids[] = {
  1229.       "0123456789-.",
  1230.       "0123456789-",
  1231.       "0123456789-.",
  1232.       "0123456789",
  1233.       "0123456789.",
  1234.       NULL
  1235.    };
  1236.  
  1237.  
  1238.    if ( ( bType >= -2 ) && ( bType <= 2 ) )
  1239.    {
  1240.       us = strspn( pszNum, pszValids[ bType+2 ] );
  1241.    }
  1242.  
  1243.    return( (BOOL)( ( us == strlen( pszNum ) ) ? TRUE : FALSE ) );
  1244. }
  1245. «ENDFILE»
  1246.  
  1247.  
  1248. «FILE:main.j»
  1249. /*
  1250.  * «APPNAME» Main   (C) «YEAR» «APPOWNER»
  1251.  *                  All Rights Under Copyright Reserved
  1252.  *
  1253.  * Version «VERSNUM»
  1254.  *
  1255.  * Written using «COMPILER»
  1256.  * Using Magic User Interface (MUI) by Stefan Stuntz
  1257.  *
  1258.  * By «APPAUTH»
  1259.  *
  1260.  *
  1261.  * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1262.  * -------  ----        --------
  1263.  *             ;
  1264.  */
  1265.  
  1266. #include "common.h"
  1267. «IF:REXX»
  1268. extern struct MUI_Command *RXCommands;
  1269. «ENDIF»
  1270.  
  1271. /*
  1272.  * GLOBAL VARIABLES ---------------------------------
  1273.  */
  1274. struct MyGlobals  MG;
  1275. char              GL_szFault[256];
  1276.  
  1277. «FOREACH:WINDOW»
  1278. struct «WSN»   «WSI»;
  1279. «ENDEACH»
  1280.  
  1281.  
  1282. /*
  1283.  * DEFINES ------------------------------------------
  1284.  */
  1285.  
  1286.  
  1287. /*
  1288.  * LIBRARY VARIABLES ---------------------------------
  1289.  */
  1290. «IF:ASL_INCL»
  1291. struct Library       *AslBase       = NULL;
  1292. «ENDIF»
  1293. «IF:DATATYPES_INCL»
  1294. struct Library       *DataTypesBase = NULL;
  1295. «ENDIF»
  1296. «IF:DISKFONT_INCL»
  1297. struct Library       *DiskfontBase  = NULL;
  1298. «ENDIF»
  1299. struct DosBase       *DosBase       = NULL;
  1300. «IF:GADTOOLS_INCL»
  1301. struct Library       *GadToolsBase  = NULL;
  1302. «ENDIF»
  1303. struct GfxBase       *GfxBase       = NULL;
  1304. struct Library       *IconBase      = NULL;
  1305. «IF:IFFPARSE_INCL»
  1306. struct Library       *IFFParseBase  = NULL;
  1307. «ENDIF»
  1308. struct IntuitionBase *IntuitionBase = NULL;
  1309. «IF:LOCALE_INCL»
  1310. struct Library       *LocaleBase    = NULL;
  1311. «ENDIF»
  1312. struct Library       *MUIMasterBase = NULL;
  1313. «IF:REALTIME_INCL»
  1314. struct Library       *RealTimeBase  = NULL;
  1315. «ENDIF»
  1316. struct Library       *UtilityBase   = NULL;
  1317. «IF:WORKBENCH_INCL»
  1318. struct Library       *WorkbenchBase = NULL;
  1319. «ENDIF»
  1320.  
  1321.  
  1322. /**
  1323.  ** M A I N   P R O G R A M -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  1324.  **/
  1325. void main(int argc, char *argv[])
  1326. {
  1327.    ULONG   signals;
  1328.    ULONG   ulInputEvent;
  1329. «MENUIF:42»   UBYTE   szPrefsSpec[ FMSIZE+2 ];«ENDIF»
  1330.    Object *aboutwin = NULL;
  1331.  
  1332.    // generic status vars
  1333.    LONG    lStat;
  1334. //   ULONG   ulStat;
  1335. //   char   *pszStat;
  1336.  
  1337.    BPTR               tmplock;
  1338.    struct WBStartup  *WBenchMsg   = NULL;
  1339.    struct WBArg      *pWBArg      = NULL;
  1340.  
  1341.    char               szProgramSpec[ FMSIZE+1 ];
  1342.  
  1343.  
  1344.    MG.running = TRUE;
  1345.  
  1346.    //
  1347.    // setup variables, read startup params, etc...
  1348.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1349.    JMH_Startup( argc, argv );
  1350.  
  1351.    //
  1352.    // attempt to create window objects and attach to application parent
  1353.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1354. «FOREACH:WINDOW»
  1355.    if ( fnConstruct«WSN»() == FALSE )   {  JMH_Quit( "Failed to create «WSI» window." );  }
  1356. «ENDEACH»
  1357.  
  1358.    //
  1359.    // Load application settings; populate global vars
  1360.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1361.    DoMethod( MG.App, MUIM_Application_Load, MUIV_Application_Load_ENV );
  1362.  
  1363.    //
  1364.    // open main window
  1365.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1366. «FOREACH:WINDOW»
  1367.    fnInit«WSN»();
  1368. «ENDEACH»
  1369.  
  1370.    //
  1371.    // if we're passed a data file, load it
  1372.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1373.    if ( argc > 1 )
  1374.    {
  1375.       if ( fnOpen( argv[1], FALSE ) == FALSE )
  1376.       {
  1377.          strcpy( MG.szProjectSpec, argv[1] );
  1378.       }
  1379.    }
  1380.    else
  1381.    {
  1382.       WBenchMsg   = (struct WBStartup *)argv;
  1383.       pWBArg      = WBenchMsg->sm_ArgList;
  1384.  
  1385.       pWBArg++;   // get first parameter
  1386.  
  1387.       if ( pWBArg )
  1388.       {
  1389.          if ( ( pWBArg->wa_Lock ) && ( *pWBArg->wa_Name ) )
  1390.          {
  1391.             tmplock  = Lock( pWBArg->wa_Name, ACCESS_READ );
  1392.             NameFromLock( tmplock, szProgramSpec, FMSIZE );
  1393.             if ( fnOpen( szProgramSpec, FALSE ) == FALSE )
  1394.             {
  1395.                strcpy( MG.szProjectSpec, szProgramSpec );
  1396.             }
  1397.             UnLock( tmplock );
  1398.          }
  1399.       }
  1400.    }
  1401.  
  1402.    //
  1403.    // show 'em what it's all 'About'
  1404.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1405.    JMH_About();
  1406.  
  1407.    //
  1408.    //   MAIN LOOP          MAIN LOOP         MAIN LOOP         MAIN LOOP
  1409.    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1410.    while ( MG.running )
  1411.    {
  1412.       ulInputEvent = DoMethod( MG.App, MUIM_Application_Input, &signals );
  1413.       switch ( ulInputEvent )
  1414.       {
  1415.          case MUIV_Application_ReturnID_Quit:
  1416.          case ID_MENU_PROJECT_QUIT:
  1417.             get( MG.App, MUIA_Application_ForceQuit, &lStat );
  1418.             if ( lStat == TRUE )
  1419.             {
  1420.                MG.running = FALSE;
  1421.             }
  1422.             else if ( MUI_Request( MG.App, MG.WIN_«WSI», 0, NULL, "OK|*Cancel",
  1423.                                    "Are you sure you want to quit?", NULL ) == 1 )
  1424.             {
  1425.                MG.running = FALSE;
  1426.             }
  1427.             break;
  1428.  
  1429.          // MENUS ---------------------------------------------
  1430. «MENUIF:01»         case ID_MENU_PROJECT_NEW:
  1431.             if ( MUI_Request( MG.App, MG.WIN_«WSI», 0, NULL, "OK|*Cancel",
  1432.                               "Are you sure you wish to clear all data?", NULL ) == 1 )
  1433.             {
  1434. //               fnNew( FALSE );
  1435.             }
  1436.             break;
  1437. «ENDIF»«MENUIF:03»         case ID_MENU_PROJECT_OPEN:
  1438.             if ( JMH_FileReq( MG.WIN_«WSI», "Open issue file", FALSE, FALSE, MG.szProjectSpec, sizeof( MG.szProjectSpec ) ) )
  1439.             {
  1440.                fnOpen( MG.szProjectSpec, FALSE );
  1441.             }
  1442.             break;
  1443. «ENDIF»«MENUIF:04»         case ID_MENU_PROJECT_SAVE:
  1444.             if ( strcmp( MG.szProjectSpec, "" ) == 0 )
  1445.             {
  1446.                JMH_FileReq( MG.WIN_«WSI», "Save issue file", TRUE, FALSE, MG.szProjectSpec, sizeof( MG.szProjectSpec ) );
  1447.             }
  1448.  
  1449.             if ( strcmp( MG.szProjectSpec, "" ) != 0 )
  1450.             {
  1451.                fnSave( MG.szProjectSpec, FALSE );
  1452.             }
  1453.             break;
  1454. «ENDIF»«MENUIF:05»         case ID_MENU_PROJECT_SAVEAS:
  1455.             if ( JMH_FileReq( MG.WIN_«WSI», "Save issue file", TRUE, FALSE, MG.szProjectSpec, sizeof( MG.szProjectSpec ) ) )
  1456.             {
  1457.                fnSave( MG.szProjectSpec, FALSE );
  1458.             }
  1459.             break;
  1460. «ENDIF»«MENUIF:07»         case ID_MENU_PROJECT_PRINT:
  1461.             break;
  1462. «ENDIF»«MENUIF:08»         case ID_MENU_PROJECT_PRINTAS:
  1463.             JMH_LaunchProgram( FALSE, "SYS:Prefs/Printer", TRUE );
  1464.             break;
  1465. «ENDIF»«MENUIF:10»         case ID_MENU_PROJECT_HIDE:
  1466.             break;
  1467. «ENDIF»«MENUIF:11»         case ID_MENU_PROJECT_REVEAL:
  1468.             break;
  1469. «ENDIF»«MENUIF:12»         case ID_MENU_PROJECT_CLOSE:
  1470.             break;
  1471. «ENDIF»«MENUIF:14»         case ID_MENU_PROJECT_ABOUT:
  1472.             JMH_About();
  1473.             break;
  1474. «ENDIF»«MENUIF:15»         case ID_MENU_PROJECT_ABOUTMUI:
  1475.             if ( !aboutwin )
  1476.             {
  1477.                aboutwin = AboutmuiObject,
  1478.                   MUIA_Window_RefWindow    , MG.WIN_«WSI»,
  1479.                   MUIA_Aboutmui_Application, MG.App,
  1480.                   End;
  1481.             }
  1482.             if ( aboutwin )
  1483.                set( aboutwin, MUIA_Window_Open, TRUE );
  1484.             else
  1485.                DisplayBeep(0);
  1486.             break;
  1487. «ENDIF»«MENUIF:17»         case ID_MENU_PROJECT_EXITLEVEL:
  1488.             break;
  1489. «ENDIF»
  1490. «MENUIF:21»         case ID_MENU_EDIT_CUT:
  1491.             break;
  1492. «ENDIF»«MENUIF:22»         case ID_MENU_EDIT_COPY:
  1493.             break;
  1494. «ENDIF»«MENUIF:23»         case ID_MENU_EDIT_PASTE:
  1495.             break;
  1496. «ENDIF»«MENUIF:25»         case ID_MENU_EDIT_ERASE:
  1497.             break;
  1498. «ENDIF»«MENUIF:27»         case ID_MENU_EDIT_UNDO:
  1499.             break;
  1500. «ENDIF»«MENUIF:28»         case ID_MENU_EDIT_REDO:
  1501.             break;
  1502. «ENDIF»
  1503. «MENUIF:30»         case ID_MENU_MACROS_STARTLEARNING:
  1504.             break;
  1505. «ENDIF»«MENUIF:31»         case ID_MENU_MACROS_STOPLEARNING:
  1506.             break;
  1507. «ENDIF»«MENUIF:32»         case ID_MENU_MACROS_ASSIGNMACRO:
  1508.             break;
  1509. «ENDIF»«MENUIF:33»         case ID_MENU_MACROS_LOAD:
  1510.             break;
  1511. «ENDIF»«MENUIF:34»         case ID_MENU_MACROS_SAVE:
  1512.             break;
  1513. «ENDIF»
  1514. «MENUIF:36»         case ID_MENU_SETTINGS_MUI:
  1515.             DoMethod( MG.App, MUIM_Application_OpenConfigWindow, 0L );
  1516.             break;
  1517. «ENDIF»«MENUIF:38»         case ID_MENU_SETTINGS_CREATEICONS:
  1518.             break;
  1519. «ENDIF»«MENUIF:40»         case ID_MENU_SETTINGS_LOAD:
  1520.             DoMethod( MG.App, MUIM_Application_Load, MUIV_Application_Load_ENV );
  1521.             break;
  1522. «ENDIF»«MENUIF:41»         case ID_MENU_SETTINGS_SAVE:
  1523.             DoMethod( MG.App, MUIM_Application_Save, MUIV_Application_Save_ENVARC );
  1524.             break;
  1525. «ENDIF»«MENUIF:42»         case ID_MENU_SETTINGS_SAVEAS:
  1526.             if ( JMH_FileReq( MG.WIN_«WSI», "Save issue file", TRUE, FALSE, szPrefsSpec, sizeof( szPrefsSpec ) ) )
  1527.             {
  1528.                DoMethod( MG.App, MUIM_Application_Save, szPrefsSpec );
  1529.             }
  1530.             break;
  1531. «ENDIF»
  1532. «MENUIF:44»         case ID_MENU_USER_MACRO1:
  1533.             break;
  1534. «ENDIF»«MENUIF:45»         case ID_MENU_USER_MACRO2:
  1535.             break;
  1536. «ENDIF»«MENUIF:46»         case ID_MENU_USER_MACRO3:
  1537.             break;
  1538. «ENDIF»«MENUIF:47»         case ID_MENU_USER_MACRO4:
  1539.             break;
  1540. «ENDIF»«MENUIF:48»         case ID_MENU_USER_MACRO5:
  1541.             break;
  1542. «ENDIF»«MENUIF:49»         case ID_MENU_USER_MACRO6:
  1543.             break;
  1544. «ENDIF»«MENUIF:50»         case ID_MENU_USER_MACRO7:
  1545.             break;
  1546. «ENDIF»«MENUIF:51»         case ID_MENU_USER_MACRO8:
  1547.             break;
  1548. «ENDIF»«MENUIF:52»         case ID_MENU_USER_MACRO9:
  1549.             break;
  1550. «ENDIF»«MENUIF:53»         case ID_MENU_USER_MACRO10:
  1551.             break;
  1552. «ENDIF»
  1553.  
  1554.          // GADGETS -------------------------------------------
  1555. «FOREACH:WINDOW»
  1556.          /***** WINDOW: «WSI»        *****/
  1557.          case ID_BUT_«WSI»_OK:
  1558.             fnDestruct«WSN»( TRUE );
  1559.             break;
  1560.          case ID_BUT_«WSI»_CANCEL:
  1561.             fnDestruct«WSN»( FALSE );
  1562.             break;
  1563. «ENDEACH»
  1564.       }
  1565.       if ( MG.running && signals ) Wait(signals);
  1566.    }
  1567.  
  1568.    set( MG.WIN_«WSI», MUIA_Window_Open, FALSE );
  1569.    JMH_Quit( NULL );
  1570. }
  1571. «ENDFILE»
  1572.  
  1573.  
  1574. «FILE:subs.j»
  1575. /*
  1576.  * «APPNAME» Windows   (C) «YEAR» «APPOWNER»
  1577.  *                     All Rights Under Copyright Reserved
  1578.  *
  1579.  * Version «VERSNUM»
  1580.  *
  1581.  * Written using «COMPILER»
  1582.  * Using Magic User Interface (MUI) by Stefan Stuntz
  1583.  *
  1584.  * By «APPAUTH»
  1585.  *
  1586.  * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1587.  * -------  ----        --------
  1588.  *             ;
  1589.  */
  1590.  
  1591. #include "common.h"
  1592.  
  1593.  
  1594. extern struct MyGlobals   MG;
  1595. extern UBYTE              GL_szFault[];
  1596.  
  1597. extern struct «WSN»  «WSI»;
  1598.  
  1599.  
  1600. BOOL fnOpen( UBYTE *pszFile, BOOL fARexx )
  1601. {
  1602.    BOOL   fError = TRUE;   // assume failure
  1603.    BPTR   fhFile;
  1604.    UBYTE  szBuf[512];
  1605.  
  1606.  
  1607.    fhFile = Open( pszFile, MODE_OLDFILE );
  1608.    if ( fhFile )
  1609.    {
  1610.       //
  1611.       // Check FILEID_HEADER
  1612.       // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1613.       if ( FGets( fhFile, szBuf, 511 ) != 0 )
  1614.       {
  1615.          szBuf[ strlen(szBuf)-1 ] = 0;
  1616.          if ( strcmp( szBuf, FILEID_HEADER ) == 0 )
  1617.          {
  1618.             //
  1619.             // Header checks out... let's read some data...
  1620.             // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1621.             fnClearMAIN();
  1622.  
  1623.             // load data here ****
  1624.  
  1625.             Close( fhFile );
  1626.  
  1627.             strcpy( MG.szProjectSpec, pszFile );
  1628.             JMH_WindowTitle( MG.WIN_«WSI» );
  1629.             fError = FALSE;
  1630.          }
  1631.          else
  1632.          {
  1633.             JMH_Error( "This is not an «APPNAME» file!", MG.WIN_«WSI», fARexx, "«HELPFILE»", "errors", 0 );
  1634.             fError = FALSE;
  1635.          }
  1636.       }
  1637.    }
  1638.  
  1639.    if ( fError )
  1640.    {
  1641.       strcpy( GL_szFault, "" );
  1642.       Fault( IoErr(), "File error!\n", GL_szFault, 255 );
  1643.       if ( strcmp( GL_szFault, "" ) == 0 )
  1644.       {
  1645.          strcpy( GL_szFault, "File Error!\n" );
  1646.       }
  1647.       sprintf( szBuf, "\nFile: %s", pszFile );
  1648.       strcat( GL_szFault, szBuf );
  1649.       JMH_Error( GL_szFault, MG.WIN_«WSI», fARexx, "«HELPFILE»", "errors", 0 );
  1650.    }
  1651.  
  1652.    return( fError );
  1653. }
  1654.  
  1655. BOOL fnSave( UBYTE *pszFile, BOOL fARexx )
  1656. {
  1657.    BOOL   fError;
  1658.    BPTR   fhFile;
  1659.    UBYTE  szBuf[512];
  1660.  
  1661.    struct DiskObject *pDObj = NULL;
  1662.  
  1663.  
  1664.    fhFile = Open( pszFile, MODE_READWRITE );
  1665.    for ( fError = TRUE; fhFile; )     // assume error; reset at end of context
  1666.    {
  1667.       if ( FPrintf( fhFile, "%s\n", FILEID_HEADER ) == -1 )       break;
  1668.       Flush( fhFile );
  1669. // **** SAVE HERE...      fError = DoMethod( MAIN.DLIS_List, MUIM_DataList_Save, fhFile );
  1670.       break;
  1671.    }
  1672.    if ( fError )
  1673.    {
  1674.       strcpy( GL_szFault, "" );
  1675.       Fault( IoErr(), "File error!\n", GL_szFault, 255 );
  1676.       if ( strcmp( GL_szFault, "" ) == 0 )
  1677.       {
  1678.          strcpy( GL_szFault, "File Error!\n" );
  1679.       }
  1680.       sprintf( szBuf, "\nFile: %s", pszFile );
  1681.       strcat( GL_szFault, szBuf );
  1682.       JMH_Error( GL_szFault, MG.WIN_«WSI», fARexx, "«HELPFILE»", "errors", 0 );
  1683.    }
  1684.    else
  1685.    {
  1686.       pDObj = GetDiskObject( MG.szProjectSpec );
  1687.       if ( !pDObj )
  1688.       {
  1689.          // don't write an icon if one already exists...
  1690.          pDObj = GetDiskObject( "env:icons/def_«APPBASE»" );
  1691.          if ( pDObj )
  1692.          {
  1693.             PutDiskObject( MG.szProjectSpec, pDObj );
  1694.             FreeDiskObject( pDObj );
  1695.          }
  1696.       }
  1697.       else
  1698.       {
  1699.          FreeDiskObject( pDObj );
  1700.       }
  1701.    }
  1702.  
  1703.    if ( fhFile )
  1704.    {
  1705.       Close( fhFile );
  1706.       JMH_WindowTitle( MG.WIN_«WSI» );
  1707.    }
  1708.  
  1709.    return( fError );
  1710. }
  1711. «ENDFILE»
  1712.  
  1713.  
  1714. «FILE:windows.j»
  1715. /*
  1716.  * «APPNAME» Windows   (C) «YEAR» «APPOWNER»
  1717.  *                     All Rights Under Copyright Reserved
  1718.  *
  1719.  * Version «VERSNUM»
  1720.  *
  1721.  * Written using «COMPILER»
  1722.  * Using Magic User Interface (MUI) by Stefan Stuntz
  1723.  *
  1724.  * By «APPAUTH»
  1725.  *
  1726.  *
  1727.  * Version~ Date~~~~~~~ Comments~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1728.  * -------  ----        --------
  1729.  *             ;
  1730.  *
  1731.  *
  1732.  * Yeah, I know, icky title!
  1733.  */
  1734.  
  1735. #include "common.h"
  1736.  
  1737.  
  1738. struct NewMenu Menu_MAINMenu[] = {
  1739. «MENULINE:00»   NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  1740. «MENULINE:01»   NM_ITEM, (STRPTR)"New"                , (STRPTR)"N", 0, 0L, (APTR)ID_MENU_PROJECT_NEW,
  1741. «MENULINE:02»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1742. «MENULINE:03»   NM_ITEM, (STRPTR)"Open"               , (STRPTR)"O", 0, 0L, (APTR)ID_MENU_PROJECT_OPEN,
  1743. «MENULINE:04»   NM_ITEM, (STRPTR)"Save"               , (STRPTR)"S", 0, 0L, (APTR)ID_MENU_PROJECT_SAVE,
  1744. «MENULINE:05»   NM_ITEM, (STRPTR)"Save As..."         , (STRPTR)"A", 0, 0L, (APTR)ID_MENU_PROJECT_SAVEAS,
  1745. «MENULINE:06»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1746. «MENULINE:07»   NM_ITEM, (STRPTR)"Print"              , (STRPTR)"P", 0, 0L, (APTR)ID_MENU_PROJECT_PRINT,
  1747. «MENULINE:08»   NM_ITEM, (STRPTR)"Print As..."        ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_PRINTAS,
  1748. «MENULINE:09»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1749. «MENULINE:10»   NM_ITEM, (STRPTR)"Hide"               ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_HIDE,
  1750. «MENULINE:11»   NM_ITEM, (STRPTR)"Reveal..."          ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_REVEAL,
  1751. «MENULINE:12»   NM_ITEM, (STRPTR)"Close"              ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_CLOSE,
  1752. «MENULINE:13»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1753. «MENULINE:14»   NM_ITEM, (STRPTR)"About..."           ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_ABOUT,
  1754. «MENULINE:15»   NM_ITEM, (STRPTR)"About MUI..."       ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_ABOUTMUI,
  1755. «MENULINE:16»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1756. «MENULINE:17»   NM_ITEM, (STRPTR)"Exit Level"         ,        NULL, 0, 0L, (APTR)ID_MENU_PROJECT_EXITLEVEL,
  1757. «MENULINE:18»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1758. «MENULINE:19»   NM_ITEM, (STRPTR)"Quit Program..."    , (STRPTR)"Q", 0, 0L, (APTR)ID_MENU_PROJECT_QUIT,
  1759. «MENULINE:20»   NM_TITLE, (STRPTR)"Edit", NULL, 0,  NULL, NULL,
  1760. «MENULINE:21»   NM_ITEM, (STRPTR)"Cut"                , (STRPTR)"X", 0, 0L, (APTR)ID_MENU_EDIT_CUT,
  1761. «MENULINE:22»   NM_ITEM, (STRPTR)"Copy"               , (STRPTR)"C", 0, 0L, (APTR)ID_MENU_EDIT_COPY,
  1762. «MENULINE:23»   NM_ITEM, (STRPTR)"Paste"              , (STRPTR)"V", 0, 0L, (APTR)ID_MENU_EDIT_PASTE,
  1763. «MENULINE:24»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1764. «MENULINE:25»   NM_ITEM, (STRPTR)"Erase"              ,        NULL, 0, 0L, (APTR)ID_MENU_EDIT_ERASE,
  1765. «MENULINE:26»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1766. «MENULINE:27»   NM_ITEM, (STRPTR)"Undo"               , (STRPTR)"Z", 0, 0L, (APTR)ID_MENU_EDIT_UNDO,
  1767. «MENULINE:28»   NM_ITEM, (STRPTR)"Redo"               ,        NULL, 0, 0L, (APTR)ID_MENU_EDIT_REDO,
  1768. «MENULINE:29»   NM_TITLE, (STRPTR)"Macros", NULL, 0, NULL, NULL,
  1769. «MENULINE:30»   NM_ITEM, (STRPTR)"Start Learning"     ,        NULL, 0, 0L, (APTR)ID_MENU_MACROS_STARTLEARNING,
  1770. «MENULINE:31»   NM_ITEM, (STRPTR)"Stop Learning"      ,        NULL, 0, 0L, (APTR)ID_MENU_MACROS_STOPLEARNING,
  1771. «MENULINE:32»   NM_ITEM, (STRPTR)"Assign Macro..."    ,        NULL, 0, 0L, (APTR)ID_MENU_MACROS_ASSIGNMACRO,
  1772. «MENULINE:33»   NM_ITEM, (STRPTR)"Load..."            ,        NULL, 0, 0L, (APTR)ID_MENU_MACROS_LOAD,
  1773. «MENULINE:34»   NM_ITEM, (STRPTR)"Save..."            ,        NULL, 0, 0L, (APTR)ID_MENU_MACROS_SAVE,
  1774. «MENULINE:35»   NM_TITLE, (STRPTR)"Settings", NULL, 0, NULL, NULL,
  1775. «MENULINE:36»   NM_ITEM, (STRPTR)"MUI..."             ,        NULL, 0, 0L, (APTR)ID_MENU_SETTINGS_MUI,
  1776. «MENULINE:37»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1777. «MENULINE:38»   NM_ITEM, (STRPTR)"Create Icons?"      ,        NULL, 0, 0L, (APTR)ID_MENU_SETTINGS_CREATEICONS,
  1778. «MENULINE:39»   NM_ITEM, (STRPTR)NM_BARLABEL          ,        NULL, 0, 0L, NULL,
  1779. «MENULINE:40»   NM_ITEM, (STRPTR)"Load Settings..."   ,        NULL, 0, 0L, (APTR)ID_MENU_SETTINGS_LOAD,
  1780. «MENULINE:41»   NM_ITEM, (STRPTR)"Save Settings"      ,        NULL, 0, 0L, (APTR)ID_MENU_SETTINGS_SAVE,
  1781. «MENULINE:42»   NM_ITEM, (STRPTR)"Save Settings As...",        NULL, 0, 0L, (APTR)ID_MENU_SETTINGS_SAVEAS,
  1782. «MENULINE:43»   NM_TITLE, (STRPTR)"User", NULL, 0, NULL, NULL,
  1783. «MENULINE:44»   NM_ITEM, (STRPTR)"Macro 1"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO1,
  1784. «MENULINE:45»   NM_ITEM, (STRPTR)"Macro 2"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO2,
  1785. «MENULINE:46»   NM_ITEM, (STRPTR)"Macro 3"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO3,
  1786. «MENULINE:47»   NM_ITEM, (STRPTR)"Macro 4"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO4,
  1787. «MENULINE:48»   NM_ITEM, (STRPTR)"Macro 5"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO5,
  1788. «MENULINE:49»   NM_ITEM, (STRPTR)"Macro 6"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO6,
  1789. «MENULINE:50»   NM_ITEM, (STRPTR)"Macro 7"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO7,
  1790. «MENULINE:51»   NM_ITEM, (STRPTR)"Macro 8"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO8,
  1791. «MENULINE:52»   NM_ITEM, (STRPTR)"Macro 9"            ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO9,
  1792. «MENULINE:53»   NM_ITEM, (STRPTR)"Macro 10"           ,        NULL, 0, 0L, (APTR)ID_MENU_USER_MACRO10,
  1793.    NM_END, NULL, NULL, 0, 0L, NULL
  1794. };
  1795.  
  1796. extern struct MyGlobals  MG;
  1797. extern char              GL_szFault[256];
  1798.  
  1799. «FOREACH:WINDOW»
  1800. extern struct «WSN»           «WSI»;
  1801. «ENDEACH»
  1802.  
  1803.  
  1804. «FOREACH:WINDOW»
  1805. //
  1806. // WINDOW: «WSI»       ---------------------------------------------------
  1807. //
  1808. /*
  1809.  * APP MESSAGE HOOK FUNCTIONS -----------------------
  1810.  */
  1811. SAVEDS ASM LONG «WSI»_AppMsgFunc( REG(a2)APTR obj, REG(a1)struct AppMessage **appmsg )
  1812. {
  1813.    struct WBArg      *ap;
  1814.    struct AppMessage *amsg = *appmsg;
  1815.    static char        buf[256];
  1816.    BOOL               fSure = TRUE;    // sure you want to load this?
  1817.  
  1818.  
  1819.    ap = amsg->am_ArgList;
  1820.    NameFromLock( ap->wa_Lock, buf, sizeof( buf ) );
  1821.    AddPart( buf, ap->wa_Name, sizeof( buf ) );
  1822.  
  1823. // add condition here to choose whether or not to put up an "Are You Sure" message
  1824.    if ( 1 )
  1825.    {
  1826.       fSure = MUI_Request( MG.App, MG.WIN_«WSI», 0, NULL, "OK|*Cancel",
  1827.                            "Data is currently loaded.\nAre you sure you want to load the new file?", NULL );
  1828.    }
  1829.    if ( fSure == TRUE )
  1830.    {
  1831.       // load data file
  1832.       if ( fnOpen( buf, FALSE ) == FALSE )
  1833.       {
  1834.          strcpy( MG.szProjectSpec, buf );
  1835.       }
  1836.    }
  1837.  
  1838.    return( 0 );
  1839. }
  1840.  
  1841. static const struct Hook «WSI»_AppMsgHook = { { NULL,NULL }, (VOID *)«WSI»_AppMsgFunc, NULL, NULL };
  1842.  
  1843. BOOL fnConstruct«WSN»( void )
  1844. {
  1845.    MG.WIN_«WSI» = WindowObject,
  1846.       MUIA_Window_ID, MAKE_ID( «WID» ),
  1847.       MUIA_Window_Title, "«WTITLE»",
  1848.       MUIA_Window_Menu, «MENUPTR»,
  1849.       MUIA_Window_AppWindow, «APPWDW»,
  1850.       MUIA_HelpNode, "«WHELP»",
  1851.       WindowContents, VGroup,
  1852.          Child, SimpleButton("---      Dummy      ---"),
  1853. //                ...
  1854.          End,
  1855.       End;
  1856.  
  1857.    if ( !MG.WIN_«WSI» )
  1858.    {
  1859.       return( FALSE );
  1860.    }
  1861.    else
  1862.    {
  1863.       // make gadget connections
  1864.       DoMethod( MG.WIN_«WSI», MUIM_Notify, MUIA_AppMessage, MUIV_EveryTime,
  1865.                 MG.App, 3, MUIM_CallHook, &«WSI»_AppMsgHook, MUIV_TriggerValue );
  1866.  
  1867.       DoMethod( MG.WIN_«WSI», MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  1868.                 MG.App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );
  1869.  
  1870.       DoMethod( «WSI».BUT_OK    , MUIM_Notify, MUIA_Pressed, FALSE, MG.App, 2, MUIM_Application_ReturnID, ID_BUT_«WSI»_OK     );
  1871.       DoMethod( «WSI».BUT_Cancel, MUIM_Notify, MUIA_Pressed, FALSE, MG.App, 2, MUIM_Application_ReturnID, ID_BUT_«WSI»_CANCEL );
  1872.  
  1873.       // set up help for menus
  1874.       DoMethod( MG.App, MUIM_Notify, MUIA_Application_MenuHelp, MUIV_EveryTime,
  1875.                 MG.App, 5, MUIM_Application_ShowHelp, MG.WIN_«WSI», "«HELPFILE»", "«MHELP»", 0 );
  1876.  
  1877.       // set tab cycle chain
  1878.       set( «WSI».BUT_OK    , MUIA_CycleChain, TRUE );
  1879.       set( «WSI».BUT_Cancel, MUIA_CycleChain, TRUE );
  1880.  
  1881. //      set( MG.WIN_«WSI», MUIA_Window_DefaultObject, «WSI».****OBJECT**** );
  1882.  
  1883.       // add window to Application object
  1884.       DoMethod( MG.App, OM_ADDMEMBER, MG.WIN_«WSI» );
  1885.  
  1886.       return( TRUE );
  1887.    }
  1888. }      
  1889.  
  1890. BOOL fnInit«WSN»( void )
  1891. {
  1892. //   set( MG.WIN_«WSI», MUIA_Window_ActiveObject, «WSI». );
  1893.    set( MG.WIN_«WSI», MUIA_Window_Open, TRUE );
  1894.  
  1895.    return( TRUE );
  1896. }
  1897.  
  1898. void fnClear«WSN»( void )
  1899. {
  1900. }
  1901.  
  1902. BOOL fnDestruct«WSN»( BOOL fOKorCANCEL )
  1903. {
  1904.    switch( fOKorCANCEL )
  1905.    {
  1906.       case TRUE:     // OK
  1907. // verify data here
  1908.          set( MG.WIN_«WSI», MUIA_Window_Open, FALSE );
  1909.          break;
  1910.       case FALSE:    // CANCEL
  1911.          set( MG.WIN_«WSI», MUIA_Window_Open, FALSE );
  1912.          break;
  1913.    }
  1914.  
  1915.    return( fOKorCANCEL );
  1916. }
  1917. «ENDEACH»
  1918. «ENDFILE»
  1919.